package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Map;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SystemConstantInfoMapper;
import com.ruoyi.db.domain.SystemConstantInfo;
import com.ruoyi.system.service.ISystemConstantInfoService;

/**
 * 系统常量信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-21
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class SystemConstantInfoServiceImpl implements ISystemConstantInfoService 
{
    @Autowired
    private SystemConstantInfoMapper systemConstantInfoMapper;
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /**
     * 查询系统常量信息
     * 
     * @param id 系统常量信息主键
     * @return 系统常量信息
     */
    @Override
    public SystemConstantInfo selectSystemConstantInfoById(Long id)
    {
        return systemConstantInfoMapper.selectSystemConstantInfoById(id);
    }

    /**
     * 查询系统常量信息列表
     * 
     * @param systemConstantInfo 系统常量信息
     * @return 系统常量信息
     */
    @Override
    public List<SystemConstantInfo> selectSystemConstantInfoList(SystemConstantInfo systemConstantInfo)
    {
        return systemConstantInfoMapper.selectSystemConstantInfoList(systemConstantInfo);
    }

    /**
     * 查询系统常量信息列表
     *
     * @param systemConstantInfo 系统常量信息
     * @return 系统常量信息
     */
    @Override
    public List<Map<String, Object>> selectSystemConstantInfoMapList(SystemConstantInfo systemConstantInfo)
    {
        return systemConstantInfoMapper.selectSystemConstantInfoMapList(systemConstantInfo);
    }

    /**
     * 新增系统常量信息
     * 
     * @param systemConstantInfo 系统常量信息
     * @return 结果
     */
    @Override
    public int insertSystemConstantInfo(SystemConstantInfo systemConstantInfo)
    {
        systemConstantInfo.setCreateTime(DateUtils.getNowDate());
        return systemConstantInfoMapper.insertSystemConstantInfo(systemConstantInfo);
    }

    /**
     * 修改系统常量信息
     * 
     * @param systemConstantInfo 系统常量信息
     * @return 结果
     */
    @Override
    public int updateSystemConstantInfo(SystemConstantInfo systemConstantInfo)
    {
        if(systemConstantInfo.getId() == 10){
            String contentInfo = systemConstantInfo.getContentInfo();
            String redisKey = "MERCHANT::PRICE::KEY";
            stringRedisTemplate.delete(redisKey);
            stringRedisTemplate.opsForValue().set(redisKey, contentInfo);
        }
        if(systemConstantInfo.getId() == 11){
            String contentInfo = systemConstantInfo.getContentInfo();
            String name = systemConstantInfo.getName();
            String redisKey1 = "APPLET::JUMP::H5::APPID";
            String redisKey2 = "APPLET::JUMP::H5::SECRET";
            stringRedisTemplate.delete(redisKey1);
            stringRedisTemplate.delete(redisKey2);
            stringRedisTemplate.opsForValue().set(redisKey1, name);
            stringRedisTemplate.opsForValue().set(redisKey2, contentInfo);
        }
        systemConstantInfo.setUpdateTime(DateUtils.getNowDate());
        return systemConstantInfoMapper.updateSystemConstantInfo(systemConstantInfo);
    }

    /**
     * 批量删除系统常量信息
     * 
     * @param ids 需要删除的系统常量信息主键
     * @return 结果
     */
    @Override
    public int deleteSystemConstantInfoByIds(Long[] ids)
    {
        return systemConstantInfoMapper.deleteSystemConstantInfoByIds(ids);
    }

    /**
     * 删除系统常量信息信息
     * 
     * @param id 系统常量信息主键
     * @return 结果
     */
    @Override
    public int deleteSystemConstantInfoById(Long id)
    {
        return systemConstantInfoMapper.deleteSystemConstantInfoById(id);
    }
}
